﻿
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>PDF.js viewer</title>

    <!-- This snippet is used in production (included from viewer.html) -->
    <link rel="resource" type="application/l10n" href="locale/locale.properties">
    <script src="~/pdf/build/pdf.js"></script>    
    <script src="~/pdf/build/pdf.worker.js"></script>    
    <script type="text/javascript">
        const CMAP_URL = '/pdf/web/cmaps/';
        const CMAP_PACKED = true;
        var pdfdoc = null;
        var renderContext = null;
        function init(url, callback){
            var loadingTask = pdfjsLib.getDocument({
                url: url,
    cMapUrl: CMAP_URL,
    cMapPacked: CMAP_PACKED
            })
            loadingTask.promise.then(function (pdf) {
                pdfdoc = pdf
                callback()
            });
            
        }
        function getPage(num) {
            pdfdoc.getPage(num).then(function (page) {
                if (renderContext) {

                } else {
                    var scale = 2
                    var viewport = page.getViewport({ scale: scale })

                    var canvas = document.getElementById('myCanvas')
                    var context = canvas.getContext('2d')
                    canvas.height = viewport.height
                    canvas.width = viewport.width

                    renderContext = {
                        canvasContext: context,
                        viewport: viewport,
                    };
                }
               
                page.render(renderContext);
            })

        }
        function loadPdf(url) {
            init(url, function (){
                getPage(1);
            });
           
        }
        function loadBody() {
            loadPdf("http://localhost:5168/api/File/download?file=BaiduNetdiskDownload\\freebook\\mix4\\Administrator\\Qi Jian Shi San Xia 1.PDF (12450)\\Qi Jian Shi San Xia 1.PDF - Administrator.pdf")
        }
        
    </script>
</head>
<body onload="loadBody()">
    <canvas id="myCanvas"></canvas>
</body>
</html>
